unit u_surcouf;

interface

uses

system.Drawing,
u_animsprite,
sysutils,
u_font,
u_load,
system.windows.Forms,
Microsoft.DirectX,
Microsoft.DirectX.Direct3D,
Microsoft.DirectX.Direct3DX;


type



t_coor_sprite_t = record
  x: integer;
  y: integer;
  euro: integer;
  text: u_text;
  cont: t_contenu;
  panier: boolean;
end;

t_tab_coor_sprite = array of t_coor_sprite_t;


c_surcouf = class

  private

    _sprite: sprite;
    fond: texture;
    fond_sur: texture;
    icone: texture;
    text_cadre: texture;
    ajout: texture;
    suppr: texture;
    petit_cadre: texture;
    cadre_ag: texture;
    selec: texture;
    baluchon: texture;

    text_euro: u_text;
    euro_panier: u_text;
    portemonai: u_text;

    b_save: c_animsprite;
    b_non: c_animsprite;
    b_oui: c_animsprite;
    t_acheter, t_passer: u_text;

    selec_bool: boolean;

    m_x, m_y: integer;
    num_tab: integer;
    _1e, _2e, _3e, _4e: boolean;

    tab_coor_sprite: t_tab_coor_sprite;

  public
    visible: boolean;
    goto_surcouf: boolean;
    menu_save: boolean;
    passe : boolean;
    constructor create(dev: device; width, height: integer);
    procedure affi_menu(height, width: integer; tab: t_tab_cont);
    procedure onclick(mousex, mousey, width, height: integer);
    procedure onresize(width, height: integer);
    procedure sur_bouton(mousex, mousey, width, height: integer);
    procedure aff_surcouf(width, height: integer;var tab: t_tab_cont);
    procedure aff_text(width, height : integer; tab: t_tab_cont);
    procedure aff_selec(x, y: integer);
    procedure click(mousex, mousey, height, width: integer; var tab: t_tab_cont);
    procedure ajouter;
    procedure suppr_panier;
    function calcul_euro: integer;
    procedure acheter(var tab: t_tab_cont);
    procedure passer;


end;


implementation
uses
  u_engine;

procedure c_surcouf.passer;
begin
  visible := false;
  goto_surcouf := false;
  menu_save := false;
  passe := true;
  myplayer.prout_etage.sur := false;
end;


function c_surcouf.calcul_euro;
var
  i: Integer;
begin
  result := 0;
  for i := 0 to length(tab_coor_sprite) - 1 do
    begin
      if tab_coor_sprite[i].panier then
        Result := Result + tab_coor_sprite[i].euro;
    end;
end;



constructor c_surcouf.create;
begin
  inherited create;
  _sprite := sprite.Create(dev);
  fond := Textureloader.FromFile(dev, 'asus menu\menu_princ\fond.png');
  icone := TextureLoader.FromFile(dev, 'asus menu\surcouf\logo_surcouf.png');
  fond_sur := TextureLoader.FromFile(dev, 'asus menu\surcouf\fond_sur.png');
  text_cadre := TextureLoader.FromFile(dev, 'asus menu\surcouf\cadre.png');
  ajout := TextureLoader.FromFile(dev, 'asus menu\surcouf\ajouter.png');
  suppr := TextureLoader.FromFile(dev, 'asus menu\surcouf\suppr.png');
  petit_cadre := TextureLoader.FromFile(dev , 'asus menu\surcouf\petit_cadre.png');
  cadre_ag := TextureLoader.FromFile(dev, 'asus menu\surcouf\cadre_ag.png');
  selec := TextureLoader.FromFile(dev, 'asus menu\surcouf\selec.png');
  baluchon := TextureLoader.FromFile(dev, 'asus menu\surcouf\baluchon.png');



  b_save := c_animsprite.create(dev, 'asus menu\menu_princ\save.png', 'asus menu\menu_princ\save_s.png', 2 * height div 5, width div 2 - 137);
  b_non := c_animsprite.create(dev, 'asus menu\menu_princ\non.png', 'asus menu\menu_princ\non1.png', 2 * height div 5 + 35, width div 2 + 5);
  b_oui := c_animsprite.create(dev, 'asus menu\menu_princ\oui.png', 'asus menu\menu_princ\oui1.png', 2 * height div 5 + 35, width div 2 - 140);
  visible := false;
  goto_surcouf := false;


  SetLength(tab_coor_sprite, 4);

  tab_coor_sprite[0].text := u_text.create(dev, 14, color.Black, '', 'Comic Sans MS', FontStyle.Regular);
  tab_coor_sprite[0].cont.nom := 'AK 47';
  tab_coor_sprite[0].cont._type := 'Armes';
  tab_coor_sprite[0].cont.carac1 := 10;
  tab_coor_sprite[0].cont.equip := false;
  tab_coor_sprite[0].cont.icone := 'asus menu\icone\arme2.png';
  tab_coor_sprite[0].cont.g_d := 'd';
  tab_coor_sprite[0].cont.carac2 := 8;
  tab_coor_sprite[0].cont.quantite := 1;
  tab_coor_sprite[0].x := 25;
  tab_coor_sprite[0].y := height div 3 + 6;
  tab_coor_sprite[0].euro := 100;
  tab_coor_sprite[0].text.change_text(tab_coor_sprite[0].cont.nom);
  tab_coor_sprite[0].panier := false;
  tab_coor_sprite[1].text := u_text.create(dev, 14, color.Black, '', 'Comic Sans MS', FontStyle.Regular);
  tab_coor_sprite[1].cont.nom := 'FX 6800 GT';
  tab_coor_sprite[1].cont._type := 'Carte graphique';
  tab_coor_sprite[1].cont.carac1 := 12;
  tab_coor_sprite[1].cont.equip := false;
  tab_coor_sprite[1].cont.icone := 'asus menu\icone\g2.png';
  tab_coor_sprite[1].cont.g_d := 'd';
  tab_coor_sprite[1].cont.quantite := 1;
  tab_coor_sprite[1].x := 25;
  tab_coor_sprite[1].y := height div 3 + 30;
  tab_coor_sprite[1].euro := 200;
  tab_coor_sprite[1].text.change_text(tab_coor_sprite[1].cont.nom);
  tab_coor_sprite[1].panier := false;
  tab_coor_sprite[2].text := u_text.create(dev, 14, color.Black, '', 'Comic Sans MS', FontStyle.Regular);
  tab_coor_sprite[2].cont.nom := 'WD caviar 200';
  tab_coor_sprite[2].cont._type := 'Disque dur';
  tab_coor_sprite[2].cont.carac1 := 10;
  tab_coor_sprite[2].cont.equip := false;
  tab_coor_sprite[2].cont.icone := 'asus menu\icone\dd200.png';
  tab_coor_sprite[2].cont.g_d := 'd';
  tab_coor_sprite[2].cont.quantite := 1;
  tab_coor_sprite[2].x := 25;
  tab_coor_sprite[2].y := height div 3 + 54;
  tab_coor_sprite[2].euro := 100;
  tab_coor_sprite[2].text.change_text(tab_coor_sprite[2].cont.nom);
  tab_coor_sprite[2].panier := false;
  tab_coor_sprite[3].text := u_text.create(dev, 14, color.Black, '', 'Comic Sans MS', FontStyle.Regular);
  tab_coor_sprite[3].cont.nom := 'intel 2GHz';
  tab_coor_sprite[3].cont._type := 'Processeur';
  tab_coor_sprite[3].cont.carac1 := 12;
  tab_coor_sprite[3].cont.equip := false;
  tab_coor_sprite[3].cont.icone := 'asus menu\icone\intel2.png';
  tab_coor_sprite[3].cont.g_d := 'd';
  tab_coor_sprite[3].x := 25;
  tab_coor_sprite[3].y := height div 3 + 78;
  tab_coor_sprite[3].euro := 150;
  tab_coor_sprite[3].text.change_text(tab_coor_sprite[3].cont.nom);
  tab_coor_sprite[3].panier := false;
  tab_coor_sprite[3].cont.quantite := 1;

  _1e := true;
  _2e := true;
  _3e := true;
  _4e := true;



  text_euro := u_text.create(dev, 14, Color.Black, '', 'Comic Sans MS', FontStyle.Regular);
  euro_panier := u_text.create(dev, 14, Color.Black, '', 'Comic Sans MS', FontStyle.Regular);
  t_acheter := u_text.create(dev, 14, Color.Black, '', 'Comic Sans MS', FontStyle.Regular);
  t_passer := u_text.create(dev, 14, Color.Black, '', 'Comic Sans MS', FontStyle.Regular);
  portemonai := u_text.create(dev, 14, Color.Black, '', 'Comic Sans MS', FontStyle.Regular);

  menu_save := false;
  goto_surcouf := false;
  selec_bool := false;
  num_tab := -1;
  passe := false;

end;

procedure c_surcouf.affi_menu;
begin
  if visible then
    begin
      if not goto_surcouf then
        begin
          _sprite.&Begin(SpriteFlags.AlphaBlend);
            _sprite.Draw(fond, Vector3.Create(0, 0 ,0), Vector3.Create(0, 0 ,0), color.White.ToArgb);
          _sprite.&End;
          if b_save.est_dehors then
            begin
              if goto_surcouf <> menu_save then
                begin
                   goto_surcouf := menu_save;
                end
              else
                begin
                  b_save.faire_venir;
                  b_non.faire_venir;
                  b_non.set_in;
                  b_oui.faire_venir;
                end;
            end;
            b_save.render;
            b_non.render;
            b_oui.render;
        end
       else
         begin
           if b_save.est_dehors then
             aff_surcouf(width, height, tab);
         end;
    end;
end;


procedure c_surcouf.onresize(width: Integer; height: Integer);
begin
  if not goto_surcouf then
    begin
      b_save.change_resolution(width, height, width div 2 - 137, 2 * height div 5);
      b_non.change_resolution(width, height, width div 2 + 5, 2 * height div 5 + 35);
      b_oui.change_resolution(width, height, width div 2 - 140, 2 * height div 5 + 35);
    end;

  if not menu_save then
    begin
      b_save.set_out;
      b_non.set_out;
      b_oui.set_out;
    end;


  if goto_surcouf then
    begin
       if not tab_coor_sprite[0].panier then
        tab_coor_sprite[0].text.set_coord(20, height div 3 + 6)
       else
        if tab_coor_sprite[0].panier then
          tab_coor_sprite[0].text.set_coord(width - 256 - 15, height div 3 + 6);

      if not tab_coor_sprite[1].panier then
        tab_coor_sprite[1].text.set_coord(20, height div 3 + 30)
      else
        if tab_coor_sprite[1].panier then
          tab_coor_sprite[1].text.set_coord(width - 256 - 15, height div 3 + 30);

      if not tab_coor_sprite[2].panier then
        tab_coor_sprite[2].text.set_coord(20, height div 3 + 54)
      else
        if tab_coor_sprite[2].panier then
          tab_coor_sprite[2].text.set_coord(width - 256 - 15, height div 3 + 54);

      if not tab_coor_sprite[3].panier then
        tab_coor_sprite[3].text.set_coord(20, height div 3 + 78)
      else
        if tab_coor_sprite[3].panier then
          tab_coor_sprite[3].text.set_coord(width - 256 - 15, height div 3 + 78);
    end;
end;

procedure c_surcouf.onclick(mousex: Integer; mousey: Integer; width: Integer; height: Integer);
begin
  if (mousex >= width div 2 + 5) and (mousex <= width div 2 + 5 + 137) and
     (mousey >= 2 * height div 5 + 35) and (mousey <= 2 * height div 5 + 35 + 15)  then
      begin
        b_save.faire_sortir;
        b_non.faire_sortir;
        b_oui.faire_sortir;
        menu_save := not goto_surcouf;
      end;
  if (mousex >= width div 2 - 140) and (mousex <= width div 2 - 140 + 137) and
     (mousey >= 2 * height div 5 + 35) and (mousey <= 2 * height div 5 + 35 + 15)  then
      begin
        b_save.faire_sortir;
        b_non.faire_sortir;
        b_oui.faire_sortir;
        menu_save := not goto_surcouf;
        // function mutun
      end
end;


procedure c_surcouf.sur_bouton(mousex: Integer; mousey: Integer; width: Integer; height: Integer);
begin
  if not goto_surcouf then
    begin
      if (mousex >= width div 2 - 137 - 10) and (mousex <= width div 2 - 137 + 275 - 10) and
         (mousey >= 2 * height div 5) and (mousey <= 2 * height div 5 + 30)  then
          begin
           if b_save.est_dedans then
             b_save.pause;
          end
      else
        b_save.play;
      if (mousex >= width div 2 + 5 - 10) and (mousex <= width div 2 + 5 + 137 - 10) and
         (mousey >= 2 * height div 5 + 35) and (mousey <= 2 * height div 5 + 35 + 15)  then
          begin
           if b_non.est_dedans then
             b_non.pause;
          end
      else
        b_non.play;
      if (mousex >= width div 2 - 140 - 10) and (mousex <= width div 2 - 140 + 137 - 10) and
         (mousey >= 2 * height div 5 + 35) and (mousey <= 2 * height div 5 + 35 + 15)  then
          begin
           if b_oui.est_dedans then
             b_oui.pause;
          end
      else
        b_oui.play;

    end;
end;



procedure c_surcouf.aff_surcouf;
begin
  _sprite.&Begin(SpriteFlags.AlphaBlend);
    _sprite.Draw(fond_sur, vector3.Create(0, 0, 0), Vector3.Create(0, 0, 0), color.White.ToArgb);
    _sprite.Draw(icone, Vector3.Create(0, 0, 0), Vector3.Create(width div 2 - 175, 40, 0), color.White.ToArgb);
    _sprite.Draw(baluchon, vector3.Create(0, 0 ,0), Vector3.Create(20, 20, 0), Color.White.ToArgb);
    _sprite.Draw(text_cadre, vector3.Create(0 ,0 ,0), Vector3.Create(20, height div 3, 0), Color.White.ToArgb);
    _sprite.Draw(text_cadre, vector3.Create(0 ,0 ,0), Vector3.Create(width - 256 - 20, Height div 3, 0), Color.White.ToArgb);
    _sprite.Draw(ajout, vector3.Create(0 ,0 ,0), Vector3.Create(width div 2 - 16, height div 3 + 100 - 36 , 0), Color.White.ToArgb);
    _sprite.Draw(suppr, vector3.Create(0 ,0 ,0), Vector3.Create(width div 2 - 16, height div 3 + 100 + 20, 0), Color.White.ToArgb);
    _sprite.Draw(petit_cadre, vector3.Create(0 ,0 ,0), Vector3.Create(width - 128 - 30, height - 64 - 50, 0), Color.White.ToArgb);
    _sprite.Draw(petit_cadre, vector3.Create(0 ,0 ,0), Vector3.Create(width - 128 - 30, height - 64 - 15, 0), Color.White.ToArgb);
    _sprite.Draw(petit_cadre, vector3.Create(0 ,0 ,0), Vector3.Create(20 + 128 - 30, height div 3 + 260, 0), Color.White.ToArgb);
    _sprite.Draw(petit_cadre, vector3.Create(0 ,0 ,0), Vector3.Create(width - 128 - 30, height div 3 + 260, 0), Color.White.ToArgb);
  _sprite.&End;
  if selec_bool then
    aff_selec(m_x, m_y);
  aff_text(width, height, tab);
end;


procedure c_surcouf.aff_text;
begin
  if not tab_coor_sprite[0].panier and _1e then
    begin
      text_euro.set_coord(20 + 256 - 100, tab_coor_sprite[0].y);
      text_euro.change_text(inttostr(tab_coor_sprite[0].euro) + ' euros');
      text_euro.text_render;
      tab_coor_sprite[0].text.set_coord(tab_coor_sprite[0].x, tab_coor_sprite[0].y);
      tab_coor_sprite[0].text.text_render
    end
  else
    if tab_coor_sprite[0].panier and _1e then
      begin
        text_euro.set_coord(width - 256 - 15 + 256 - 100, tab_coor_sprite[0].y);
        text_euro.change_text(inttostr(tab_coor_sprite[0].euro) + ' euros');
        text_euro.text_render;
        tab_coor_sprite[0].text.set_coord(width - 256 - 15, tab_coor_sprite[0].y);
        tab_coor_sprite[0].text.text_render;
      end;
  if not tab_coor_sprite[1].panier and _2e then
    begin
      text_euro.set_coord(20 + 256 - 100, tab_coor_sprite[1].y);
      text_euro.change_text(inttostr(tab_coor_sprite[1].euro) + ' euros');
      text_euro.text_render;
      tab_coor_sprite[1].text.set_coord(tab_coor_sprite[1].x, tab_coor_sprite[1].y);
      tab_coor_sprite[1].text.text_render
    end
  else
    if tab_coor_sprite[1].panier and _2e then
      begin
        text_euro.set_coord(width - 256 - 15 + 256 - 100, tab_coor_sprite[1].y);
        text_euro.change_text(inttostr(tab_coor_sprite[1].euro) + ' euros');
        text_euro.text_render;
        tab_coor_sprite[1].text.set_coord(width - 256 - 15, tab_coor_sprite[1].y);
        tab_coor_sprite[1].text.text_render;
      end;
  if not tab_coor_sprite[2].panier and _3e then
    begin
      text_euro.set_coord(20 + 256 - 100, tab_coor_sprite[2].y);
      text_euro.change_text(inttostr(tab_coor_sprite[2].euro) + ' euros');
      text_euro.text_render;
      tab_coor_sprite[2].text.set_coord(tab_coor_sprite[2].x, tab_coor_sprite[2].y);
      tab_coor_sprite[2].text.text_render
    end
  else
    if tab_coor_sprite[2].panier and _3e then
      begin
        text_euro.set_coord(width - 256 - 15 + 256 - 100, tab_coor_sprite[2].y);
        text_euro.change_text(inttostr(tab_coor_sprite[2].euro) + ' euros');
        text_euro.text_render;
        tab_coor_sprite[2].text.set_coord(width - 256 - 15, tab_coor_sprite[2].y);
        tab_coor_sprite[2].text.text_render;
      end;
  if not tab_coor_sprite[3].panier and _4e then
    begin
      text_euro.set_coord(20 + 256 - 100, tab_coor_sprite[3].y);
      text_euro.change_text(inttostr(tab_coor_sprite[3].euro) + ' euros');
      text_euro.text_render;
      tab_coor_sprite[3].text.set_coord(tab_coor_sprite[3].x, tab_coor_sprite[3].y);
      tab_coor_sprite[3].text.text_render
    end
  else
    if tab_coor_sprite[3].panier and _4e then
      begin
        text_euro.set_coord(width - 256 - 15 + 256 - 100, tab_coor_sprite[3].y);
        text_euro.change_text(inttostr(tab_coor_sprite[3].euro) + ' euros');
        text_euro.text_render;
        tab_coor_sprite[3].text.set_coord(width - 256 - 15, tab_coor_sprite[3].y);
        tab_coor_sprite[3].text.text_render;
      end;
  portemonai.set_coord(20 + 128 - 23, height div 3 + 262);
  portemonai.change_text('banque :' + inttostr(tab[0].quantite));
  euro_panier.set_coord(width - 128 - 23, height div 3 + 262);
  euro_panier.change_text(inttostr(calcul_euro) + ' euros');
  euro_panier.text_render;
  t_passer.set_coord(width - 128 - 23, height - 64 - 15);
  t_passer.change_text('passer');
  t_passer.text_render;
  t_acheter.set_coord(width - 128 - 23, height - 64 - 50);
  t_acheter.change_text('acheter');
  t_acheter.text_render;
end;


procedure c_surcouf.aff_selec(x: Integer; y: Integer);
begin
  _sprite.&Begin(SpriteFlags.AlphaBlend);
    _sprite.Draw(selec, Vector3.Create(0, 0 ,0), Vector3.Create(x, y, 0), color.White.ToArgb);
  _sprite.&End
end;


procedure c_surcouf.click;
begin
  if (mousex >= 20) and (mousex <= 20 + 256) and
     (mousey >= height div 3 + 1) and (mousey <= height div 3 + 1 + 25) and _1e then
     begin
       m_x := 20;
       m_y := height div 3 + 1;
       selec_bool := true;
       num_tab := 0;
     end;
  if (mousex >= 20) and (mousex <= 20 + 256) and
     (mousey >= height div 3 + 26) and (mousey <= height div 3 + 1 + 50) and _2e then
     begin
       m_x :=20;
       m_y := height div 3 + 26;
       selec_bool := true;
       num_tab := 1;
     end;
  if (mousex >= 20) and (mousex <= 20 + 256) and
     (mousey >= height div 3 + 51) and (mousey <= height div 3 + 1 + 75) and _3e then
     begin
       m_x := 20;
       m_y := height div 3 + 51;
       selec_bool := true;
       num_tab := 2;
     end;
  if (mousex >= 20) and (mousex <= 20 + 256) and
     (mousey >= height div 3 + 76) and (mousey <= height div 3 + 1 + 100) and _4e then
     begin
       m_x := 20;
       m_y := height div 3 + 76;
       selec_bool := true;
       num_tab := 3;
     end;
  if (mousex >= width - 256 - 20) and (mousex <= width - 256 - 20 + 256) and
     (mousey >= height div 3 + 1) and (mousey <= height div 3 + 1 + 25) and _1e then
     begin
       m_x := width - 256 - 20;
       m_y := height div 3 + 1;
       selec_bool := true;
       num_tab := 0;
     end;
  if (mousex >= width - 256 - 20) and (mousex <= width - 256 - 20 + 256) and
     (mousey >= height div 3 + 26) and (mousey <= height div 3 + 1 + 50) and _2e then
     begin
       m_x := width - 256 - 20;
       m_y := height div 3 + 26;
       selec_bool := true;
       num_tab := 1;
     end;
  if (mousex >= width - 256 - 20) and (mousex <= width - 256 - 20 + 256) and
     (mousey >= height div 3 + 51) and (mousey <= height div 3 + 1 + 75) and _3e then
     begin
       m_x := width - 256 - 20;
       m_y := height div 3 + 51;
       selec_bool := true;
       num_tab := 2;
     end;
  if (mousex >= width - 256 - 20) and (mousex <= width - 256 - 20 + 256) and
     (mousey >= height div 3 + 76) and (mousey <= height div 3 + 1 + 100) and _4e then
     begin
       m_x := width - 256 - 20;
       m_y := height div 3 + 76;
       selec_bool := true;
       num_tab := 3;
     end;
  if (mousex >= width div 2 - 16) and (mousex <= width div 2 - 16 + 32) and
     (mousey >= height div 3 + 100 - 36) and (mousey <= height div 3 + 100 - 36 + 16)then
     begin
       if selec_bool then
        begin
         ajouter;
         selec_bool := false;
        end;
     end;
  if (mousex >= width div 2 - 16) and (mousex <= width div 2 - 16 + 32) and
     (mousey >= height div 3 + 100 + 20) and (mousey <= height div 3 + 100 + 20 + 16)then
     begin
       if selec_bool then
        begin
         suppr_panier;
         selec_bool := false;
        end;
     end;
  if (mousex >= width - 128 - 30) and (mousex <= width - 128 - 30 + 128) and
     (mousey >= height - 64 - 50) and (mousey <= height - 64 - 50 + 32)then
     begin
        begin
         acheter(tab);
         selec_bool := false;
        end;
     end;
  if (mousex >= width - 128 - 30) and (mousex <= width - 128 - 30 + 128) and
     (mousey >= height - 64 - 15) and (mousey <= height - 64 - 15 + 32)then
     begin
       passer;
       selec_bool := false;
     end;
end;



procedure c_surcouf.ajouter;
begin
  tab_coor_sprite[num_tab].panier := true;
end;

procedure c_surcouf.suppr_panier;
begin
  tab_coor_sprite[num_tab].panier := false;
end;


procedure c_surcouf.acheter;
var
  i, j: Integer;
  _or: integer;
begin
  _or := calcul_euro;
  if tab[0].quantite >= calcul_euro then
    begin
      for i := 0 to length(tab_coor_sprite) - 1 do
        begin
          if tab_coor_sprite[i].panier then
            begin
              case i of
                0: _1e := false;
                1: _2e := false;
                2: _3e := false;
                3: _4e := false;
              end;
              SetLength(tab, length(tab) + 1);
              tab[high(tab)] := tab_coor_sprite[i].cont;
              mymesh.modif_tab_cont := true;
//              tab_coor_sprite[i] := tab_coor_sprite[high(tab_coor_sprite)];
//              SetLength(tab_coor_sprite, length(tab_coor_sprite) - 1);

            end;
        end;
      visible := false;
      goto_surcouf := false;
      menu_save := false;
      passe := true;
      myplayer.prout_etage.sur := false;
      tab[0].quantite := tab[0].quantite - _or;
    end;
end;

end.
